package com.etc.tools;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DBTools {
	private final static String DRIVER = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:oracle:thin:@//localhost:1521/XE"; 
	private static String user = "scott"; 
	private static String password = "tiger";
	
	public Connection getConnection() {
		Connection conn =  null;
		//使用反射将驱动类加载到内存
		try {
			Class.forName(DRIVER);
			conn = DriverManager.getConnection(url, user, password);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		//获取到数据库的连接
		return conn;
	}
	
	public void closeConnection(Connection conn) {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}


